home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Sources / FWAutoDe.cpp next >
Encoding:
Text File  |  1994-04-21  |  5.3 KB  |  152 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWAutoDe.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef   FWAUTODE_H
  13. #include "FWAutoDe.h"
  14. #endif
  15.  
  16. #if defined(FW_USE_NEW_HELPER) && !defined(FWNEWHEL_H)
  17. #include "FWNewHel.h"
  18. #endif
  19.  
  20. #ifndef FWEXCTAS_H
  21. #include "FWExcTas.h"
  22. #endif
  23.  
  24. #ifndef FWPRIDEB_H
  25. #include "FWPriDeb.h"
  26. #endif
  27.  
  28. #ifdef FW_BUILD_MAC
  29. #pragma segment BEL
  30. #endif
  31.  
  32. #ifdef FW_BUILD_WIN
  33. #define FW_qUsePlatformAlloc
  34. #endif
  35.  
  36. //========================================================================================
  37. // CLASS _FW_CAutoDestructObject
  38. //========================================================================================
  39.  
  40. #ifdef __BORLANDC__
  41. //----------------------------------------------------------------------------------------
  42. // _FW_CAutoDestructObject::__Delete
  43. //----------------------------------------------------------------------------------------
  44. void _FW_CAutoDestructObject::__Delete()
  45. {
  46.     // Borland C++ 3.1 is bizzare, too.  It will call operator delete in any case, but
  47.     //    not intentionally, but simply because it forgets to push the argument for
  48.     //    the destructor on the stack
  49.     __asm {
  50.         push    0                        // this is the argument that the compiler forgets
  51.         push    word ptr[this + 2]        // push the address
  52.         push    word ptr[this]
  53.         les        bx, [this]                // get the object pointer
  54.         les        bx, dword ptr es:[bx]    // get the vtable pointer
  55.         call    dword ptr es:[bx]        // and call the dtor
  56.         add        sp, 6                    // clean up the stack
  57.     };
  58. }
  59. #endif    
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // _FW_CAutoDestructObject::~_FW_CAutoDestructObject
  63. //----------------------------------------------------------------------------------------
  64. _FW_CAutoDestructObject::~_FW_CAutoDestructObject()
  65. {
  66. }
  67.  
  68. #ifdef FW_USE_NEW_HELPER    
  69. //----------------------------------------------------------------------------------------
  70. // _FW_CAutoDestructObject::operator new
  71. //----------------------------------------------------------------------------------------
  72. void* _FW_CAutoDestructObject::operator new(size_t size, const _FW_CPrivNewHelper &helper)
  73. {
  74. #ifdef FW_qUsePlatformAlloc
  75.     void *p = ::operator new(size);
  76. #else
  77.     FW_PRIV_ASSERT(helper.fNewHandler != NULL);
  78.     FW_PRIV_ASSERT(helper.fDeleteHandler != NULL);
  79.  
  80.     if (GetOperatorNewHandler() == NULL)
  81.     {
  82.         SetOperatorNewHandler(helper.fNewHandler);
  83.         SetOperatorDeleteHandler(helper.fDeleteHandler);
  84.     }
  85.     FW_PRIV_ASSERT(helper.fNewHandler == GetOperatorNewHandler());
  86.     FW_PRIV_ASSERT(helper.fDeleteHandler == GetOperatorDeleteHandler());
  87.     __FW_OperatorNewHandler operatorNewHandler = helper.fNewHandler;
  88.     void *p = operatorNewHandler(size);
  89. #endif
  90.     
  91.     helper.WatchObject((_FW_CAutoDestructObject*)p, size);
  92.     
  93.     return p;
  94. }
  95. #endif
  96.  
  97. #ifdef FW_USE_NEW_HELPER    
  98. //----------------------------------------------------------------------------------------
  99. // _FW_CAutoDestructObject::operator delete
  100. //----------------------------------------------------------------------------------------
  101. void _FW_CAutoDestructObject::operator delete(void *object)
  102. {
  103. #ifdef FW_qUsePlatformAlloc
  104.     ::operator delete(object);
  105. #else
  106.     __FW_OperatorDeleteHandler operatorDeleteHandler = GetOperatorDeleteHandler();
  107.     FW_PRIV_ASSERT(operatorDeleteHandler != NULL);
  108.     operatorDeleteHandler(object);
  109. #endif
  110. }
  111. #endif
  112.  
  113. //----------------------------------------------------------------------------------------
  114. // _FW_CAutoDestructObject::SetOperatorNewHandler
  115. //----------------------------------------------------------------------------------------
  116. void _FW_CAutoDestructObject::SetOperatorNewHandler(__FW_OperatorNewHandler operatorNewHandler)
  117. {
  118.     FW_SPrivExceptionGlobals& globals = FW_CExceptionTaskGlobals::GetExceptionGlobals();
  119.     FW_PRIV_ASSERT(globals.gOperatorNewHandler == NULL);
  120.     globals.gOperatorNewHandler = operatorNewHandler;
  121. }
  122.  
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // _FW_CAutoDestructObject::SetOperatorDeleteHandler
  126. //----------------------------------------------------------------------------------------
  127.  
  128. void _FW_CAutoDestructObject::SetOperatorDeleteHandler(__FW_OperatorDeleteHandler operatorDeleteHandler)
  129. {
  130.     FW_SPrivExceptionGlobals& globals = FW_CExceptionTaskGlobals::GetExceptionGlobals();
  131.     FW_PRIV_ASSERT(globals.gOperatorDeleteHandler == NULL);
  132.     globals.gOperatorDeleteHandler = operatorDeleteHandler;
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // _FW_CAutoDestructObject::GetOperatorNewHandler
  137. //----------------------------------------------------------------------------------------
  138. __FW_OperatorNewHandler _FW_CAutoDestructObject::GetOperatorNewHandler()
  139. {
  140.     return FW_CExceptionTaskGlobals::GetExceptionGlobals().gOperatorNewHandler;
  141. }
  142.  
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // _FW_CAutoDestructObject::GetOperatorDeleteHandler
  146. //----------------------------------------------------------------------------------------
  147.  
  148. __FW_OperatorDeleteHandler _FW_CAutoDestructObject::GetOperatorDeleteHandler()
  149. {
  150.     return FW_CExceptionTaskGlobals::GetExceptionGlobals().gOperatorDeleteHandler;
  151. }
  152.